package com.dbsun.service.st;

import com.dbsun.common.ServerResponse;
import com.dbsun.entity.system.Page;
import com.dbsun.entity.system.PageData;
import com.dbsun.mapper.st.Small_studentMapper;
import com.dbsun.service.BaseService;
import com.dbsun.util.Tools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class Small_studentService extends BaseService {
    @Autowired
    private Small_studentMapper Small_studentMapper;

    public List<PageData> getPageSmall_studentList(Page page) {
        return Small_studentMapper.getPageSmall_studentList(page);
    }

    public ServerResponse<List<PageData>> getSmall_studentList(PageData pd) {
        if (Tools.isObjEmpty("111")) {
            return ServerResponse.badArgument();
        }
        return ServerResponse.createBySuccess(Small_studentMapper.getSmall_studentList(pd));
    }

    @Transactional
    public ServerResponse<String> addSmall_student(PageData pd) {
        int rowCount = Small_studentMapper.addSmall_student(pd);
        if (rowCount > 0) {
            return ServerResponse.createBySuccessMessage("添加成功");
        }
        return ServerResponse.createByErrorMessage("添加失败");
    }

    @Transactional
    public ServerResponse<String> updateSmall_studentByid(PageData pd) {
        if (Tools.isObjEmpty(pd.get("id"))) {
            return ServerResponse.createByErrorMessage("修改参数错误");
        }
        int rowCount = Small_studentMapper.updateSmall_studentByid(pd);
        if (rowCount > 0) {
            return ServerResponse.createBySuccessMessage("修改成功");
        }
        return ServerResponse.createByErrorMessage("修改失败");
    }

    public ServerResponse<PageData> getSmall_studentByColumn(PageData pd) {
        if (Tools.isObjEmpty(pd.get("id"))) {
            return ServerResponse.createByErrorMessage("获取数据参数错误");
        }
        return ServerResponse.createBySuccess(Small_studentMapper.getSmall_studentByColumn(pd));
    }

    public ServerResponse<String> deleteSmall_studentByColumn(PageData pd) {
        if (Tools.isObjEmpty(pd.get("id"))) {
            return ServerResponse.createByErrorMessage("删除参数错误");
        }
        int rowCount = Small_studentMapper.deleteSmall_studentByColumn(pd);
        if (rowCount > 0) {
            return ServerResponse.createBySuccessMessage("删除成功");
        }
        return ServerResponse.createByErrorMessage("删除失败");
    }
}
